package com.recruit.recommend.controller;


import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.recruit.recommend.service.ChatAiService;
import io.github.talelin.core.annotation.PermissionModule;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/recruit/chatAi")
@PermissionModule(value = "职位")
@Slf4j
public class ChatAiController {

    private final static Logger logger = LoggerFactory.getLogger(ChatAiController.class);

    @Autowired
    private ChatAiService chatAiService;

    @GetMapping("/{question}")
    public Flux<ServerSentEvent<String>> generateArticle(@PathVariable String question, HttpServletResponse response) throws NoApiKeyException, InputRequiredException {
        Flux<ServerSentEvent<String>> generationResult = chatAiService.generate(question,response);
        log.info(generationResult.toString());
        return generationResult;
    }

}
